#include "point.h"

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

double distance(Point * p1, Point * p2){
   return sqrt((p2->x - p1->x) * (p2->x - p1->x) + (p2->y - p1->y) * (p2->y - p1->y));
}

double dot(Point * p1, Point * p2){
   return p1->x * p2->x + p1->y * p2->y;
}

int compare(Point * p1, Point * p2){
   if(p2->x > p1->x){
      return 1;
   } else if(p2->x < p1->x){
      return -1;
   } else{
      if(p2->y > p1->y)
		return 1;
      else if(p2->y < p1->y)
		return -1;
      else return 0;
   }
}

int isCoplanarWithPoints(Point * o, Point * p1, Point * p2){
  //printf("diff = %g\n", abs((p2->x-p1->x)*(o->y-p1->y)-(p2->y-p1->y)*(o->x-p1->x)));
   if(fabs((p2->x-p1->x)*(o->y-p1->y)-(p2->y-p1->y)*(o->x-p1->x)) < EPS)
      return 1;
   else
      return 0;
}

int halfPlane(Point * o, Point * p1, Point * p2){
	double diff = (p2->x-p1->x)*(o->y-p1->y)-(p2->y-p1->y)*(o->x-p1->x);
	if(diff < 0)
		return -1;
	else if(diff > 0)
		return 1;
	else
		return 0;
}

void printPoint(Point * p){
	printf("Point[x=%g, y=%g, used=%d]\n", p->x, p->y, p->used);
}

Point * newPoint(){
	Point * p = (Point *)malloc(sizeof(Point));
	p->used = 0;
	return p;
}

/*
int main(){
   Point * p1 = (Point *)malloc(sizeof(Point));
   Point * p2 = (Point *)malloc(sizeof(Point));

   p1->x = 2.0;
   p1->y = 2.0;

   p2->x = 4.0;
   p2->y = 4.0;

   printf("distance = %g\n", distance(p1, p2));
   printf("dot = %g\n", dot(p1, p2));
   printf("compare = %d\n", compare(p1, p2));
   return 0;
}*/

